package com.tencent.wxcloudrun.config;

import lombok.Data;

import java.util.HashMap;

@Data
public final class ErrorResult<T> {
    private String message;
    private Boolean success;
    private Object data;

    private ErrorResult (String message, boolean success, T data) {
        this.message = message;
        this.success = success;
        this.data = data;
    }

    /**
     * @TODO 登录超时
     * @param data
     * @return
     */
    public static ErrorResult loginTimeOut (Object data) {
        return new ErrorResult(
                ResultEnum.LOGIN_TIME_OUT.getMessage(),
                ResultEnum.LOGIN_TIME_OUT.getSuccess(),
                data
                );
    }

    /**
     * @TODO 权限不足
     * @param data
     * @return
     */
    public static ErrorResult insufficientPrivileges (Object data) {
        return new ErrorResult(
                ResultEnum.INSUFFICIENT_PRIVILEGES.getMessage(),
                ResultEnum.INSUFFICIENT_PRIVILEGES.getSuccess(),
                data
        );
    }

    /**
     * @TODO 系统错误
     * @param data
     * @return
     */
    public static ErrorResult systemError (Object data) {
        return new ErrorResult(
                ResultEnum.SYSTEM_ERROR.getMessage(),
                ResultEnum.SYSTEM_ERROR.getSuccess(),
                data != null ? data : new HashMap<>()
        );
    }
}
